package com.cnsoft.model.communal;

import javax.annotation.Resource;

import org.cnsoft.framework.beans.common.RESTResultBean;
import org.cnsoft.framework.constants.ECCodeMessageConstants;
import org.cnsoft.framework.db.page.PageModel;
import org.cnsoft.framework.support.MyPageControllerSupport;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.cnsoft.persistent.communal.R702030MaterialTag.R702030MaterialTagDBO;
import com.cnsoft.persistent.communal.R702030MaterialTag.R702030MaterialTagDao;
import com.cnsoft.persistent.communal.R702030MaterialTag.R702030MaterialTagPVO;

/**
 * 文章资讯标签信息页面控制逻辑
 */
@Controller
@RequestMapping(value = "/page/1.0/base/r702030materialtag", method = { RequestMethod.POST })
public class R702030MaterialTagPageController extends MyPageControllerSupport { // MyTokenCommonSupport
	@Resource
	private R702030MaterialTagDao daoR702030MaterialTag;

	// private MyModelAndViewSupport model =
	// super.getModelAndView("R702030_material_tag");

	// 一览（分页查询）
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	public ModelAndView doList(R702030MaterialTagPVO param, PageModel<R702030MaterialTagDBO> pageModel, RESTResultBean<String> message) throws Exception {
		// 输出参数日志
		logger.debug("param=====>>>>" + param.toJsonString());
		// 设定展示界面
		ModelAndView modelAndView = getModelAndView("/communal/R702030MaterialTag-list");
		pageModel.setFormParamBean(param);
		// 开启记录数统计
		// pageModel.setResultCountFlag(true);
		// 排序模式
		// pageModel.setOrderbyCreateTimeDESC();
		// 分页查询
		daoR702030MaterialTag.doSelectPage(pageModel);
		// 设定返回
		modelAndView.addObject("page", pageModel);
		modelAndView.addObject("param", param);
		modelAndView.addObject("message", message);
		return modelAndView;
	}

	// 打开新增页面
	@RequestMapping(value = "/append", method = RequestMethod.POST)
	public ModelAndView doAppend(R702030MaterialTagPVO param, PageModel<R702030MaterialTagDBO> pageModel, RESTResultBean<String> message) throws Exception {
		// 设定展示界面
		ModelAndView modelAndView = getModelAndView("/communal/R702030MaterialTag-item");
		// 页面模式设定
		modelAndView.addObject("mode", ONE);
		return modelAndView;
	}

	// 打开编辑页面
	@RequestMapping(value = "/modify", method = RequestMethod.POST)
	public ModelAndView doModify(R702030MaterialTagPVO param, PageModel<R702030MaterialTagDBO> pageModel, RESTResultBean<String> message) throws Exception {
		// 输出参数日志
		logger.debug("param=====>>>>" + param.toJsonString());
		// 设定展示界面
		ModelAndView modelAndView = getModelAndView("/communal/R702030MaterialTag-item");
		// 页面模式设定
		modelAndView.addObject("mode", TWO);
		// 数据查询
		modelAndView.addObject("data", daoR702030MaterialTag.doRead(param));
		return modelAndView;
	}

	// 删除数据
	@RequestMapping(value = "/discard", method = RequestMethod.POST)
	public ModelAndView doDiscard(R702030MaterialTagPVO param, PageModel<R702030MaterialTagDBO> pageModel, RESTResultBean<String> message) throws Exception {
		// 输出参数日志
		logger.debug("param=====>>>>" + param.toJsonString());
		// 信息删除
		daoR702030MaterialTag.doDelete(param);
		message.setResult(ECCodeMessageConstants.MESSAGE_DB_DELETE);
		return doList(new R702030MaterialTagPVO(), pageModel, message);
	}

	// 数据保存
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public ModelAndView doSave(String mode, R702030MaterialTagPVO param, PageModel<R702030MaterialTagDBO> pageModel, RESTResultBean<String> message) throws Exception {
		// 输出参数日志
		logger.debug("param=====>>>>" + param.toJsonString());
		// 判断操作类别
		if (ONE.equals(mode)) { // 新增
			daoR702030MaterialTag.doInsertSelective(param);
			message.setResult(ECCodeMessageConstants.MESSAGE_DB_INSERT);
		} else { // 编辑
			daoR702030MaterialTag.doUpdate(param);
			message.setResult(ECCodeMessageConstants.MESSAGE_DB_UPDATE);
		}
		// 设定展示界面
		ModelAndView modelAndView = getModelAndView("/communal/pageform-saas");
		// 页面提示信息设定
		modelAndView.addObject("message", message);
		// 目标展示页面
		modelAndView.addObject("target", "/page/1.0/base/r702030materialtag/list");
		return modelAndView;
	}

}
